package org.firebug.spring.boot.metadata.repository.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.firebug.spring.boot.metadata.repository.po.DictionaryPO;

import java.util.List;

@Mapper
public interface DictionaryDAO {
    @Insert("insert into t_dictionary (pcode,code,name,value,sectors,enabled) values (#{pcode},#{code},#{name},#{value},#{sectors},#{enabled})")
    int insert(DictionaryPO po);

    @Select("select * from t_dictionary where code=#{code}")
    DictionaryPO selectByCode(@Param("code") String code);

    @Select("select * from t_dictionary where pcode=#{pcode} and enabled=true")
    List<DictionaryPO> selectByPcode(@Param("pcode") String pcode);

    @Select("select * from t_dictionary where pcode=#{pcode} and enabled=true and sectors & 1<<${sector}")
    List<DictionaryPO> selectByPcodeSector(@Param("pcode") String pcode, @Param("sector") int sector);
}
